#include "E53_IA1.h"

SHT31 sht30;
// BH1750 lightMeter(0x23);
void E53_IA1_init(void)
{
// 开启与智慧农业板块相连的I2C引脚
  Wire.begin(I2C_SDA_PIN,I2C_SCL_PIN);
  sht30.begin(I2C_SDA_PIN,I2C_SCL_PIN);
//   if (lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) {
//     Serial.println(F("BH1750 Advanced begin"));
//   } else {
//     Serial.println(F("Error initialising BH1750"));
//   }
  uint16_t stat = sht30.readStatus();
  Serial.print(stat, HEX);
  Serial.println();
  delay(300);
  
}

/*函数名称: ReadData
*说明: 读取E53_IA1的温度、湿度和光照数据
*参数: 无
*返回值:包含三个数据的结构体Data
*/
Data E53_IA1_ReadData(){
    //获取光照强度
    // float lux = lightMeter.readLightLevel();
    //获取温湿度
    Serial.println("test");

    sht30.read();   

    float temperature = sht30.getTemperature();
    float humidity = sht30.getHumidity();
    Serial.println("test1");

    Data data;
    data.hum = humidity;
    data.temp = temperature;
    // data.light = lux;
    Serial.printf("temp:%.2f, humi:%.2f", temperature, humidity);
    return data;
}

/*函数名称: ReadData
*说明: 读取E53_IA1的温度、湿度和光照数据
*参数: 无
*返回值:包含三个数据的结构体Data
*/
void E53_IA1_ReadData(Data* data){
    //获取温湿度
    sht30.read();   

    float temperature = sht30.getTemperature();
    float humidity = sht30.getHumidity();
    Serial.println("test1");

    // Data data;
    data->hum = humidity;
    data->temp = temperature;
    Serial.printf("temp:%.2f, humi:%.2f", data->temp, data->hum);
    // return data;
}